export function verify(a,b,modifiers){
	let patt = new RegExp("(,|^)(" + b.join("|").replace(/(\.|\?|\*|\\|\^|\$)/g,"\\$1") + ")(,|$)");
	return (a.join(',').match(patt) || ["","",""])[2]
}
// 两个数组获取相同值
export function getSames(a,b,modifiers){ 
	let patt = new RegExp("(?<=,|^)(" + b.join("|").replace(/(\.|\?|\*|\\|\^|\$)/g,"\\$1") + ")(?=,|$)",'g');
	return b ? (a.join(',').match(patt) || []) : [];
}
// 两个数组从第一个数组获取第二个数组没有的值
export function getNotSames(a,b,modifiers){ 
	let patt = new RegExp("(?<=,|^)(" + b.join("|").replace(/(\.|\?|\*|\\|\^|\$)/g,"\\$1") + ")(,|$)",'g');
	let result = a.join(',').replace(patt,'').replace(/(^,*)|(,*$)/g,'')
	return result  ? result.split(',') : []
}
// 根据身份证号码解析获取出生年月日及年龄和性别
export function idCardCodeToInfoData(no) {
	if (!no || !
		/^(^[1-9]\d{7}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}$)|(^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])((\d{4})|\d{3}[Xx])$)$/
		.test(no)) return undefined;
	const toStr = no.toString()
	const yearStr = toStr.substring(6, 10)
	const dateStr = `${toStr.substring(10, 12)}-${toStr.substring(12, 14)}`
	const birthy = `${yearStr}-${dateStr}`
	const birth = new Date(birthy)
	const today = new Date()
	let age = today.getFullYear() - birth.getFullYear()
	if (
		today.getMonth() < birth.getMonth() ||
		(today.getMonth() == birth.getMonth() && today.getDate() < birth.getDate())
	) {
		age--
	}
	const sex = Number(toStr.substring(16, 17)) % 2 ? '男' : '女'
	return {
		birthy,
		age,
		sex
	}
}
//获取url格式字符串参数
export function getUrlParams(url,paramName){
	let patt = new RegExp(`([?&]|^)${paramName}=([^&#]*)`)
	return (url.match(patt) || ["","",""])[2];
}
// 验证手机号码是正确
export function isPhone(phoneStr) {
	return /^(13[0-9]|15[012356789]|166|17[3678]|18[0-9]|19[0-9]|14[57])[0-9]{8}$/.test(phoneStr)
}
// 数字转为金额格式
export function toThousands(num) {
	// .replace(/(?<=^\d+)(\d{3})(?=(\d{3})*(\.\d+)?$)/g,",$1")
	// .replace(/(?<=^\d*)(\d)(?=(\d{3})+(\.\d+)?$)/g,"$1,")
	return (num || 0).toString().replace(/(?<=^\d*)(\d)(?=(?:\d{3})+(?:[^\d].+)?$)/g, '$1,');
}

// 匹配年月日时分秒
export function formatDate(str="", format) {
	return str.replace(/(\d{4})?[^\d]*(\d{1,2})?[^\d]*(\d{1,2})?[^\d]*(\d{1,2})?[^\d]*(\d{1,2})?[^\d]*(\d{1,2})?/, format);
}

// 敏感字符脱敏
export function toPrivacy(str, start = 1, end, replacement = " * ") {
	if (str != "" && str.length > 1) {
		let replaceStr = str.substring(start, end);
		return str.replace(replaceStr, replacement.repeat(replaceStr.length));
	} else {
		return str;
	}
}

// 当前环境是否是pc端
export function isPC(){
	return navigator && /windows|macintosh/i.test(navigator.userAgent)
}